package com.hieubq.demo.screenlock.theme.snail.activity;

import java.util.Calendar;

import com.hieubq.demo.screenlock.theme.snail.receiver.ScheduleReceiver;
import com.hieubq.demo.screenlock.theme.snail.service.MonitorService;
import com.hieubq.demo.screenlock.theme.snail.R;

import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

public class ScreenOnOff extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		
		setContentView(R.layout.activity_screen_on_off);
		
		AlarmManager service = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
		Intent i = new Intent(this, ScheduleReceiver.class);
		PendingIntent pending = PendingIntent.getBroadcast(this, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
		Calendar cal = Calendar.getInstance();
		// Start 30 seconds after boot completed
		cal.add(Calendar.SECOND, 5);
		//
		// Fetch every 30 seconds
		// InexactRepeating allows Android to optimize the energy consumption
		service.setInexactRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), com.hieubq.demo.screenlock.theme.snail.receiver.StartupReceiver.REPEAT_TIME, pending);
		
		Toast.makeText(this, "start service,", Toast.LENGTH_SHORT).show();
		this.startService(new Intent(this, MonitorService.class));
		finish();
		
	}	
	
}